package com.huifaapp.mall.adapter;

import android.content.Context;
import android.content.Intent;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.TextView;

import com.huifaapp.mall.R;
import com.huifaapp.mall.activity.AlreadyPayActivity;
import com.huifaapp.mall.activity.OrderdetailsActivity;
import com.huifaapp.mall.bean.PendingCommBean;

import java.util.List;

/**
 * Created by mac on 2017/12/8.
 */

public class PendingCommAdapter extends RecyclerView.Adapter<PendingCommAdapter.MyViewHolder> {
    private Context context;
    private MyViewHolder myViewHolder;
    //  private List<PendingCommBean.DataBean> goods;
    private List<PendingCommBean.OrderListBean> list;
    int position;

    public PendingCommAdapter(Context context, List<PendingCommBean.OrderListBean> list) {
        this.context = context;
        this.list = list;
    }

    @Override
    public PendingCommAdapter.MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view= LayoutInflater.from(context).inflate(R.layout.pendcomm_item,null);
        myViewHolder = new MyViewHolder(view);
        return myViewHolder;
    }

    @Override
    public void onBindViewHolder(PendingCommAdapter.MyViewHolder holder, final int position) {
        if (okItck != null) {
            myViewHolder.itemView.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    okItck.okck(myViewHolder.itemView, myViewHolder.getLayoutPosition());
                }
            });
            myViewHolder.bt_delete.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    okItck.delete(view,position);

                }
            });
           myViewHolder.btevaluate.setOnClickListener(new View.OnClickListener() {
               @Override
               public void onClick(View v) {
                   okItck.xiangqing(v,position);
               }
           });

//            myViewHolder.btevaluate.setOnClickListener(new View.OnClickListener() {
//                @Override
//                public void onClick(View view) {
//                    okItck.asaes(myViewHolder.itemView,position);
//                }
//            });
//


        }
        final PendingCommBean.OrderListBean orderListBean = list.get(position);   //获取当前条目的数据
        List<PendingCommBean.OrderListBean.DataBean> data = orderListBean.getData();   //获取到内层的数据集合
        PendingCommAdaptertwo pendingCommAdaptertwo = new PendingCommAdaptertwo(context, data);   //创建内层的适配器



        pendingCommAdaptertwo.setOnItemClickListener(new PendpayAdaptertwo.OnItemClickListenertwo() {
            @Override
            public void OnItem(View view, int position) {
                Intent intent = new Intent(context, OrderdetailsActivity.class);
                intent.putExtra("orderNo",orderListBean.getOrderNo());
                context.startActivity(intent);
                Log.e("hhhhhhh",orderListBean.getOrderNo()+"");
            }
        });




        holder.recy111.setAdapter(pendingCommAdaptertwo);   //绑定内层的适配器
        holder.sum_count.setText("共计" + orderListBean.getTotalcount() + "件商品");   //商品的总个数
        holder.sum_money.setText("合计: ¥" + orderListBean.getTotalprice());   //商品的总价
        holder.yunfei.setText("(含运费¥ " + orderListBean.getExpressFee() + ")");   //商品的运费
        holder.order_num.setText("订单编号: " + orderListBean.getOrderNo() + ""); // 订单编号

    }

    @Override
    public int getItemCount() {
        return list.size();
    }

    public class MyViewHolder extends RecyclerView.ViewHolder {
        RecyclerView recy111;
        TextView yunfei, sum_money, sum_count,order_num;
        Button bt_delete;
        Button btevaluate;
        public MyViewHolder(final View itemView) {
            super(itemView);

            recy111 = (RecyclerView) itemView.findViewById(R.id.pendcomm_recy);
            recy111.setLayoutManager(new LinearLayoutManager(context));
            yunfei = (TextView) itemView.findViewById(R.id.pendcomm_hyf);
            sum_money = (TextView) itemView.findViewById(R.id.pendcomm_hj);
            sum_count = (TextView) itemView.findViewById(R.id.pendcomm_gj);
            bt_delete = (Button) itemView.findViewById(R.id.pendcomm_delete);
            order_num = (TextView) itemView.findViewById(R.id.pendcomm_orderNumText);


            btevaluate = (Button) itemView.findViewById(R.id.chakanxiangqing);

            btevaluate.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    Intent intent = new Intent(context, OrderdetailsActivity.class);
                    intent.putExtra("orderNo",list.get(position).getOrderNo()+"");
                    context.startActivity(intent);
                }
            });
//            btevaluate.setOnClickListener(new View.OnClickListener() {
//                @Override
//                public void onClick(View view) {
//                    Intent intent = new Intent(context, AssessActivity.class);
//                    intent.putExtra("orderNo",list.getOrderNo());
//                    context.startActivity(intent);
//
//
//                }
//            });
        }
    }
    public interface OkItck{
        void okck(View view,int position);
        void delete(View view, int position);
        void asaes(View view, int position);
        void xiangqing(View view,int position);


    }
    private OkItck okItck;

    public void setOkItck(OkItck okItck){
        this.okItck = okItck;
    }
}
